home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / ASTRONOM / H139.ZIP / UI101.ZIP / IO / KB / KB_CPM.C < prev    next >
C/C++ Source or Header  |  1991-11-04  |  6KB  |  283 lines

  1. /*************************************************************************
  2.  
  3.     kb_cpm.c    Keyboard (KB) Subroutines
  4.                for Bywater Software
  5.  
  6.             Implementation for CP/M computers
  7.             (should work on all CP/M 2.2 machines).
  8.             utilizing the Eco-C (tm) compiler 
  9.  
  10.             Copyright (c) 1991, Ted A. Campbell
  11.  
  12.             Bywater Software
  13.             P. O. Box 4023 
  14.             Duke Station 
  15.             Durham, NC  27706
  16.  
  17.             email: tcamp@hercules.acpub.duke.edu
  18.  
  19.     WARNING:        THIS IS AN OUTMODED FILE, unused in most
  20.             recent versions of this software, or not
  21.             yet updated and verified to latest revision
  22.             levels. Use at your own risk. It should not
  23.             be distributed publicly.
  24.  
  25.     Copyright and Permissions Information:
  26.  
  27.     All U.S. and international copyrights are claimed by the
  28.     author. The author grants permission to use this code
  29.     and software based on it under the following conditions:
  30.     (a) in general, the code and software based upon it may be 
  31.     used by individuals and by non-profit organizations; (b) it
  32.     may also be utilized by governmental agencies in any country,
  33.     with the exception of military agencies; (c) the code and/or
  34.     software based upon it may not be sold for a profit without
  35.     an explicit and specific permission from the author, except
  36.     that a minimal fee may be charged for media on which it is
  37.     copied, and for copying and handling; (d) the code must be 
  38.     distributed in the form in which it has been released by the
  39.     author; and (e) the code and software based upon it may not 
  40.     be used for illegal activities. 
  41.  
  42. **************************************************************************/
  43.  
  44. #include "kb.h"
  45.  
  46. #ifndef CR
  47. #define    CR    0x0d
  48. #define LF    0x0a
  49. #define    ESC    0x1b
  50. #endif
  51.  
  52. #define    DELBACK    0x08
  53.  
  54. int cpm_hold = 0;
  55.  
  56. /*************************************************************************
  57.  
  58.     FUNCTION:       kb_init()
  59.  
  60.     DESCRIPTION:    This function should perform any initialization
  61.             necessary for the keyboard system.
  62.  
  63.     INPUT:          none.
  64.  
  65.     RETURNS:        none.
  66.  
  67. **************************************************************************/
  68.  
  69. kb_init()
  70.     {
  71.     }
  72.  
  73. /*************************************************************************
  74.  
  75.     FUNCTION:       kb_deinit()
  76.  
  77.     DESCRIPTION:    This function should perform any necessary
  78.             deinitialization, that is, return the keyboard
  79.             to its default state when a Simple Software
  80.             program is to be exited.
  81.  
  82.     INPUT:          none.
  83.  
  84.     RETURNS:        none.
  85.  
  86. **************************************************************************/
  87.  
  88. kb_deinit()
  89.     {
  90.     }
  91.  
  92. /*************************************************************************
  93.  
  94.     FUNCTION:       kb_cis()
  95.  
  96.     DESCRIPTION:    This function determines whether a character is
  97.             ready from the console.  The function is used
  98.             especially in telecommunications programs,
  99.             where it is necessary to poll the keyboard
  100.             without locking up the program waiting for a
  101.             response.
  102.  
  103.     INPUT:          none.
  104.  
  105.     RETURNS:        The function returns 0 if no character is
  106.             available and 1 if a character is available.
  107.  
  108. **************************************************************************/
  109.  
  110. kb_cis()
  111.     {
  112.     register int c;
  113.     if ( ( c = _bdos( 0x06, 0xff ) ) == 0 )
  114.         {
  115.         cpm_hold = 0;
  116.         return 0;
  117.         }
  118.     else
  119.         {
  120.         cpm_hold = c;
  121.         return 1;
  122.         }
  123.     }
  124.  
  125. /*************************************************************************
  126.  
  127.     FUNCTION:       kb_ci()
  128.  
  129.     DESCRIPTION:    This function returns a single character from
  130.             the keyboard.  If a character is not available
  131.             it waits.  The function should be able to
  132.             recognize any special keys, and return the
  133.             appropriate Simple Software KB conventions
  134.             designated for them.
  135.  
  136.     INPUT:          none.
  137.  
  138.     RETURNS:        The function returns the ASCII code for the
  139.             key pressed, or the Simple Software KB convention
  140.             (see kb.h) for a function or other special key.
  141.  
  142. **************************************************************************/
  143.  
  144. kb_ci()
  145.     {
  146.     int c;
  147.     if ( cpm_hold != 0 )
  148.         {
  149.         c = cpm_hold;
  150.         cpm_hold = 0;
  151.         return c;
  152.         }
  153.     while ( ( c = _bdos( 0x06, 0xff )) == 0 )
  154.         ;
  155.     if ( ( c >= 0x20 ) && ( c < 0x7f ) )
  156.         {
  157.         return c;
  158.         }
  159.     else
  160.         {
  161.         switch ( c )
  162.             {
  163.             case 0x05:
  164.                 return KB_UP;
  165.                 break;
  166.             case 0x18:
  167.                 return KB_DOWN;
  168.                 break;
  169.             case 0x13:
  170.                 return KB_LEFT;
  171.                 break;
  172.             case 0x04:
  173.                 return KB_RIGHT;
  174.                 break;
  175.             case 0x12:
  176.                 return KB_P_UP;
  177.                 break;
  178.             case 0x03:
  179.                 return KB_P_DOWN;
  180.                 break;
  181.             case 0x16:
  182.                 return KB_INSERT;
  183.                 break;
  184.             case 0x07:
  185.                 return KB_DELETE;
  186.                 break;
  187.             case 0x01:
  188.                 return KB_FK3;
  189.                 break;
  190.             case 0x06:
  191.                 return KB_FK4;
  192.                 break;
  193.             case 0x19:
  194.                 return KB_FK5;
  195.                 break;
  196.             case 0x14:
  197.                 return KB_FK6;
  198.                 break;
  199.             case 0x0b:
  200.             case ESC:
  201.                 return cpm_esc();
  202.                 break;
  203.             case CR:
  204.             case LF:
  205.             case DELBACK:
  206.                 return c;
  207.                 break;
  208.             default:
  209.                 return 0;
  210.                 break;
  211.             }
  212.         }
  213.     }
  214.  
  215. /*************************************************************************
  216.  
  217.     FUNCTION:       cpm_esc()
  218.  
  219.     DESCRIPTION:    This function handles escape sequences from the
  220.             keyboard.  It calls the kb_emenu() function
  221.             (defined by the application program), accepts
  222.             a new command letter, then replace the menu
  223.             with kb_dmenu (the default menu defined by
  224.             the application program).
  225.  
  226.     INPUT:          none.
  227.  
  228.     RETURNS:        The function returns the Simple Software
  229.             convention for a special key sequence (see
  230.             kb.h), or 0.
  231.  
  232. **************************************************************************/
  233.  
  234. cpm_esc()
  235.     {
  236.     register int c;
  237.     while ( ( c = _bdos( 0x06, 0xff ) ) == 0 )
  238.         ;
  239.     switch ( c )
  240.         {
  241.         case '1':
  242.             return KB_FK1;
  243.             break;
  244.         case '2':
  245.             return KB_FK2;
  246.             break;
  247.         case '3':
  248.             return KB_FK3;
  249.             break;
  250.         case '4':
  251.             return KB_FK4;
  252.             break;
  253.         case '5':
  254.             return KB_FK5;
  255.             break;
  256.         case '6':
  257.             return KB_FK6;
  258.             break;
  259.         case '7':
  260.             return KB_FK7;
  261.             break;
  262.         case '8':
  263.         case 'Q':
  264.         case 'q':
  265.             return KB_FK8;
  266.             break;
  267.         case '9':
  268.         case 'S':
  269.         case 's':
  270.             return KB_FK9;
  271.             break;
  272.         case '0':
  273.         case 'D':
  274.         case 'd':
  275.             return KB_FK10;
  276.             break;
  277.         default:
  278.             return 0;
  279.             break;
  280.         }
  281.     }
  282.  
  283.